<?
include_once('common/autoload.php');
// include_once('class/abc/')
$list=$_REQUEST["list"];
$act=$_REQUEST["act"];
$tpl=Tpl::getLink();
if($act=="del"){
	foreach($list as $v){
		if(($res=$tpl->del($v))!==true){
			echo "<script>alert('".$res."')</script>";
			exit;
		}
	}
	echo "<script>alert('删除成功');parent.window.location='tpllist.html';</script>";
}
elseif($act=="rule"){

	write_logs(json_encode($_REQUEST));
	// exit;
	$tt=$_REQUEST["title"];
	$nt=$_REQUEST["note"];

	foreach($tt as $k=>$title){
		$note=$nt[$k];
		if(strlen($note)>120){
			echo "<script>alert('".$title."备注信息超过30字');</script>";
			exit;
		}
		if(!empty($note) && p_match($note)){
			echo "<script>alert('".$title."备注存在非法字符!');</script>";
			exit;
		}
		if(p_match($title)){
			echo "<script>alert('".$title."标题存在非法字符!');</script>";
			exit;
		}
		$upd="update uu_fx_pri_tpl set title='".$title."',note='".$note."' where id=".$k;
		$GLOBALS['le']->query($upd);
	}
	echo "<script>alert('保存成功');</script>";
}

function write_logs($txt,$file="/var/www/html/new/d/abc/logs/hhhh.txt"){
	$fp = fopen($file,"a");
	flock($fp, LOCK_EX);
	fwrite($fp,date("Y-m-d H:i:s").":".$txt."\n");
	flock($fp, LOCK_UN);
	fclose($fp);
}
?>